package com.whut.mobilesafe.db.dao;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.io.File;

/**
 * 作    者：yubo.xiaoyubo
 * 时    间：2016/1/2  11:21.
 * 版    本：1.0
 * 描    述：
 */
public class AntiVirtusDao {
    private static final String DBNAME = "antivirus.db";
    private static final String TABLENAME = "datable";

    // 根据应用apk文件的地址，查询是否是病毒
    public static boolean querybyApkSourceDir(Context context, String md5) {

        //打开数据库只可以从data/data目录下打开，不可以从assets目录下打开
        File filesDir = context.getFilesDir();
        File targetFile = new File(filesDir, DBNAME);
        SQLiteDatabase db = SQLiteDatabase.openDatabase(targetFile.getAbsolutePath(), null, SQLiteDatabase.OPEN_READONLY);

        Cursor cursor = db.rawQuery("select * from datable where md5=?",
                new String[] { md5 });

        boolean isVirus = false;
        if (cursor.moveToFirst()) {
            isVirus = true;
        }

        cursor.close();
        db.close();


        return isVirus;
    }

}
